

public class ListQueue implements Queue {

	private LinkedList list;
	
	
	public ListQueue() {
		list = new LinkedList();
	}


	public void enqueue( Object x ) {
		list.insert( x, list.getLast() );
	}

	
	public Object dequeue() {
		if ( isEmpty() ) {
			throw new IllegalStateException();
		}
		ListNode first = list.getFirst();
		Object x = first.getElement();
		list.remove( first );
		return x;
	}

	
	public Object first() {
		if ( isEmpty() ) {
			throw new IllegalStateException();
		}
		ListNode first = list.getFirst();
		return first.getElement();
	}

	
	public boolean isEmpty() {
		return list.isEmpty();
	}

	
	public void clear() {
		list.clear();
	}

}
